<!DOCTYPE html>
<head>
{if isset($buildData) && isset($buildData['buildForm'])}
<link rel="stylesheet" href="__PUBLIC_PACK__/layui/css/layui.css?v={:config('builder.version')}" media="all">
<link rel="stylesheet" href="__PUBLIC_STATIC__/p_builder/css/save.css?v={:config('builder.version')}">
{if !isset($buildData['buildForm']['hiData']['pop'])}
<style>.layui-form-item .layui-form-label{width: 8%;}</style>
{/if}
<script src="__PUBLIC_PACK__/layui/layui.js?v={:config('builder.version')}"></script>
<script>
    layui.use(['element', 'form'], function() {
        var element = layui.element;
        var form = layui.form;
    });
    layui.config({
        base: '__PUBLIC_PACK__/layui_admin/',
        version: '{:config("builder.version")}'
    }).extend({
        layuihi: "layuihi",
        base: "base",
        func: "func",
        md5: "md5",
    }).use(['base']);
    function goback(){
        window.location.href = document.referrer.replace(window.location.protocol+"//"+window.location.host,"");
    }
</script>
</head>
<body>
{if !isset($tabType) || !$tabType}
<div class="buildForm">
{/if}
<form class="layui-form" action="{:$buildData['buildForm']['action']}" method="{$buildData['buildForm']['method']}">
    <div class="page-form">
        {volist name="buildData['buildForm']['items']" id="v"}
        {switch name="v['type']"}
        {case value="line"}
        <!--标题分割线-->
        <div class="layui-form-item">
            <div class="site-title">
            <fieldset class="layui-elem-field layui-field-title">
                <legend>{$v['title']}</legend>
            </fieldset>
            </div>
        </div>
        {/case}
        {case value="textarea"}
        <!--多行文本-->
        <div class="layui-form-item">
            <label class="layui-form-label">{$v['title']}</label>
            <div class="layui-input-inline">
                <textarea rows="6"  class="layui-textarea field-{$v['name']}" name="{$v['name']}" autocomplete="off"{if isset($v['verify'])} lay-verify="{$v['verify']}"{/if} placeholder="{if isset($v['placeholder'])}{$v['placeholder']}{else/}请填写{$v['title']}{/if}"{if isset($v['attribute']) && $v['attribute']} {$v['attribute']}{/if}>{if isset($v['value'])}{:htmlspecialchars_decode($v['value'])}{/if}</textarea>
            </div>
            <div class="layui-form-mid layui-word-aux">{if isset($v['tips'])}{:htmlspecialchars_decode($v['tips'])}{/if}</div>
        </div>
        {/case}
        {case value="array"}
        <!--文本域-->
        <div class="layui-form-item">
            <label class="layui-form-label">{$v['title']}</label>
            <div class="layui-input-inline">
                <textarea rows="6" class="layui-textarea field-{$v['name']}" name="{$v['name']}" autocomplete="off" placeholder="{if isset($v['placeholder'])}{$v['placeholder']}{else/}请填写{$v['title']}{/if}"{if isset($v['verify'])} lay-verify="{$v['verify']}"{/if}>{if isset($v['value'])}{:$v['value']}{/if}</textarea>
            </div>
            <div class="layui-form-mid layui-word-aux">{if isset($v['tips'])}{:htmlspecialchars_decode($v['tips'])}{/if}</div>
        </div>
        {/case}
        {case value="switch"}
        <!--开关-->
        <div class="layui-form-item">
            <label class="layui-form-label">{$v['title']}</label>
            <div class="layui-input-inline">
                <input type="checkbox" class="field-{$v['name']}" name="{$v['name']}" value="1" lay-skin="switch"{if isset($v['filter'])} lay-filter="{$v['filter']}"{/if}{if isset($v['verify'])} lay-verify="{$v['verify']}"{/if} lay-text="{$v['options'][1]}|{$v['options'][0]}" {if isset($v['value']) && $v['value'] == 1}checked=""{/if}>
            </div>
            <div class="layui-form-mid layui-word-aux">{if isset($v['tips'])}{:htmlspecialchars_decode($v['tips'])}{/if}</div>
        </div>
        {/case}
        {case value="select"}
        <!--下拉框-->
        <div class="layui-form-item">
            <label class="layui-form-label">{$v['title']}</label>
            <div class="layui-input-inline">
                <select type="select" class="field-{$v['name']}" name="{$v['name']}"{if isset($v['filter'])} lay-filter="{$v['filter']['name']}" hi-filter-title="{$v['filter']['title']}" hi-filter-tips="{$v['filter']['tips']}" hi-filter-field="{$v['filter']['field']}" hi-filter-action="{$v['filter']['action']}"{/if}{if isset($v['verify'])} lay-verify="{$v['verify']}"{/if}{if isset($v['attribute']) && $v['attribute']} {$v['attribute']}{/if}>
                    {foreach $v['options'] as $key=>$vv}
                    <option value="{$key}" {if isset($v['value']) && $key == $v['value']}selected{/if}>{$vv}</option>
                    {/foreach}
                </select>
            </div>
            <div class="layui-form-mid layui-word-aux">{if isset($v['tips'])}{:htmlspecialchars_decode($v['tips'])}{/if}</div>
        </div>
        {/case}
        {case value="radio"}
        <!--单选-->
        <div class="layui-form-item">
            <label class="layui-form-label">{$v['title']}</label>
            <div class="layui-input-inline">
                {foreach $v['options'] as $key=>$vv}
                <input type="radio" class="field-{$v['name']}" name="{$v['name']}" value="{$key}" title="{$vv}"{if isset($v['filter'])} lay-filter="{$v['filter']['name']}" hi-filter-title="{$v['filter']['title']}" hi-filter-tips="{$v['filter']['tips']}" hi-filter-field="{$v['filter']['field']}" hi-filter-action="{$v['filter']['action']}"{/if}{if isset($v['value']) && $key == $v['value']}checked{/if}{if isset($v['attribute']) && $v['attribute']} {$v['attribute']}{/if}>
                {/foreach}
            </div>
            <div class="layui-form-mid layui-word-aux">{if isset($v['tips'])}{:htmlspecialchars_decode($v['tips'])}{/if}</div>
        </div>
        {/case}
        {case value="checkbox"}
        <!--多选-->
        <div class="layui-form-item">
            <label class="layui-form-label">{$v['title']}</label>
            <div class="layui-input-inline">
                {foreach $v['options'] as $key=>$vv}
                <input type="checkbox" class="field-{$v['name']}" name="{$v['name']}[]" value="{$key}" title="{$vv}" lay-skin="primary" {if isset($v['value']) && $v['value'] && in_array($key, parseAttr($v['value']))}checked{/if}>
                {/foreach}
            </div>
            <div class="layui-form-mid layui-word-aux">{if isset($v['tips'])}{:htmlspecialchars_decode($v['tips'])}{/if}</div>
        </div>
        {/case}
        {case value="inputMulti"}
        <!--复合表单-->
        <div class="layui-form-item">
            <label class="layui-form-label">{$v['title']}</label>
            <div class="layui-input-inline input-multi-inline">
                {if $v['options']}
                <fieldset class="layui-elem-field check-multi">
                    <div class="layui-field-box field-{$v['name']}" type="inputMulti">
                        {foreach $v['options'] as $key=>$vv}
                        <div class="layui-inline">
                            <label class="layui-form-label">{$vv['name']}</label>
                            <div class="layui-input-inline">
                            {if $vv['options'] == ''}
                            <input type="text" class="layui-input field-text-{$v['name']}" name="{$v['name']}[{$vv['name']}]" placeholder="" autocomplete="off">
                            {else}
                                {if $vv['type'] == 'radio'}
                                    {foreach $vv['options'] as $kk=>$vvv}
                                    <input type="radio" class="field-radio-{$v['name']}" name="{$v['name']}[{$vv['name']}]" value="{$vvv}" title="{$vvv}">
                                    {/foreach}
                                {else}
                                    {foreach $vv['options'] as $kk=>$vvv}
                                    <input type="checkbox" class="field-checkbox-{$v['name']}" name="{$v['name']}[{$vv['name']}][]" value="{$vvv}" title="{$vvv}" lay-skin="primary">
                                    {/foreach}
                                {/if}
                            {/if}
                            </div>
                            <div class="layui-form-mid layui-word-aux">{if isset($vv['tips'])}{:htmlspecialchars_decode($vv['tips'])}{/if}</div>
                        </div>
                        {/foreach}
                    </div>
                </fieldset>
                {/if}
            </div>
        </div>
        {/case}
        {case value="date"}
        <!--日期-->
        <div class="layui-form-item">
            <label class="layui-form-label">{$v['title']}</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input layui-date field-{$v['name']}" name="{$v['name']}" value="{if isset($v['value'])}{$v['value']}{/if}" autocomplete="off" placeholder="{if isset($v['placeholder'])}{$v['placeholder']}{else/}请填写{$v['title']}{/if}"{if isset($v['verify'])} lay-verify="{$v['verify']}"{/if}>
            </div>
            <div class="layui-form-mid layui-word-aux">{if isset($v['tips'])}{:htmlspecialchars_decode($v['tips'])}{/if}</div>
        </div>
        {/case}
        {case value="datetime"}
        <!--日期+时间-->
        <div class="layui-form-item">
            <label class="layui-form-label">{$v['title']}</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input layui-date-time field-{$v['name']}" name="{$v['name']}" value="{if isset($v['value'])}{$v['value']}{/if}" autocomplete="off" placeholder="{if isset($v['placeholder'])}{$v['placeholder']}{else/}请填写{$v['title']}{/if}"{if isset($v['verify'])} lay-verify="{$v['verify']}"{/if}>
            </div>
            <div class="layui-form-mid layui-word-aux">{if isset($v['tips'])}{:htmlspecialchars_decode($v['tips'])}{/if}</div>
        </div>
        {/case}
        {case value="image"}
        <!--图片-->
        <div class="layui-form-item">
            <label class="layui-form-label">{$v['title']}</label>
            <div class="layui-input-inline upload">
                <button type="button" name="upload" class="layui-btn layui-btn-primary layui-upload" data-url="{if isset($v['url'])}{$v['url']}{/if}" lay-data="{accept:'image'}" lay-type="image">上传单图</button>
                <input type="hidden" class="upload-input" name="{$v['name']}" value="{if isset($v['value'])}{$v['value']}{/if}"{if isset($v['verify'])} lay-verify="{$v['verify']}"{/if}>
                {if condition="$v['value']"}
                <img src="{$v['value']}" type="img" class="field-{$v['name']}" style="display:inline-block;border-radius:5px;border:1px solid #ccc" width="36" height="36">
                {else /}
                <img src="" style="display:none;border-radius:5px;border:1px solid #ccc" type="img" class="field-{$v['name']}" width="36" height="36">
                {/if}
            </div>
            <div class="layui-form-mid layui-word-aux">{if isset($v['tips'])}{:htmlspecialchars_decode($v['tips'])}{/if}</div>
        </div>
        {/case}
        {case value="multi"}
        <!--多图-->
        <div class="layui-form-item">
            <label class="layui-form-label">{$v['title']}</label>
            <div class="layui-input-inline upload">
                <button type="button" class="layui-btn layui-btn-primary layui-upload" lay-data="{accept:'image'}" data-url="{if isset($v['url'])}{$v['url']}{/if}" multi-field="{$v['name']}" multi-type="true" lay-type="image">上传多图</button>
                <div class="pic-items">
                    <img src="" type="multi" class="field-{$v['name']}" style="display: none">
                    <ul class="pic-items-upload-list multi-priview">
                    </ul>
                </div>
            </div>
            <div class="layui-form-mid layui-word-aux">{if isset($v['tips'])}{:htmlspecialchars_decode($v['tips'])}{/if}</div>
        </div>
        {/case}
        {case value="file"}
        <!--文件-->
        <div class="layui-form-item">
            <label class="layui-form-label">{$v['title']}</label>
            <div class="layui-input-inline upload">
                <button type="button" name="upload" class="layui-btn layui-btn-primary layui-upload" data-url="{if isset($v['url'])}{$v['url']}{/if}" lay-data="{accept:'file'}" lay-type="file">点击上传文件</button>
                <input type="hidden" class="upload-input" name="{$v['name']}" value="{if isset($v['value'])}{$v['value']}{/if}"{if isset($v['verify'])} lay-verify="{$v['verify']}"{/if}>
                <span type="file" class="field-{$v['name']}"></span>
            </div>
            <div class="layui-form-mid layui-word-aux">{if isset($v['tips'])}{:htmlspecialchars_decode($v['tips'])}{/if}</div>
        </div>
        {/case}
        {case value="color"}
        <div class="layui-form-item">
            <label class="layui-form-label">{$v['title']}</label>
            <div class="layui-input-inline">
                <input type="text" class="field-{$v['name']}" name="{$v['name']}" value="{if isset($v['value'])}{$v['value']}{/if}" placeholder="{if isset($v['placeholder'])}{$v['placeholder']}{else/}请选择颜色{/if}" class="layui-input color_{$v['name']}"{if isset($v['verify'])} lay-verify="{$v['verify']}"{/if}>
            </div>
            <div class="layui-inline">
                <div class="color-form-{$v['name']}"></div>
            </div>
            <div class="layui-form-mid layui-word-aux">{if isset($v['tips'])}{:htmlspecialchars_decode($v['tips'])}{/if}</div>
        </div>
        <script type="application/javascript">
            layui.use(['colorpicker'], function() {
                var $ = layui.jquery, colorpicker = layui.colorpicker;
                colorpicker.render({
                    elem: '.color-form-{$v["name"]}'
                    ,color: '{if $v["value"]}{$v["value"]}{else/}#1c97f5{/if}'
                    ,done: function(color){
                        $('.color_{$v["name"]}').val(color);
                    }
                });
            })
        </script>
        {/case}
        {case value="password"}
        <div class="layui-form-item">
            <label class="layui-form-label">{$v['title']}</label>
            <div class="layui-input-inline">
                <input type="password" class="layui-input field-{$v['name']}" name="{$v['name']}" autocomplete="off" placeholder="{if isset($v['placeholder'])}{$v['placeholder']}{/if}"{if isset($v['verify'])} lay-verify="{$v['verify']}"{/if}{if isset($v['attribute']) && $v['attribute']} {$v['attribute']}{/if}>
            </div>
            <div class="layui-form-mid layui-word-aux">{if isset($v['tips'])}{:htmlspecialchars_decode($v['tips'])}{/if}</div>
        </div>
        {/case}
        {case value="hidden"}
        <input type="hidden" class="field-{$v['name']}" name="{$v['name']}" value="{if isset($v['value'])}{$v['value']}{/if}">
        {/case}
        {case value="editor"}
        <div class="layui-form-item">
            <label class="layui-form-label">{$v['title']}</label>
            <div class="layui-input-inline hi-editor">
                {if isset($v['editor'])}
                    {php}
                    $editorGroup = '';
                    $editorValue = '';
                    if(isset($buildData["buildForm"]["upload_group"])){
                        $editorGroup = $buildData["buildForm"]["upload_group"];
                    }
                    if(isset($formData) && !empty($formData[$v['name']])){
                        $editorValue = $formData[$v['name']];
                    }
                    {/php}
                   {:runHook($v['editor'], ['group'=>$editorGroup, 'name'=>$v['name'], 'value'=>$editorValue])}
                {/if}
            </div>
        </div>
        {/case}
        {case value="html"}
        <div class="layui-form-item">
            <label class="layui-form-label">{$v['title']}</label>
            <div class="layui-input-inline item-html">
                {if isset($v['value'])}{:htmlspecialchars_decode($v['value'])}{/if}
            </div>
            <div class="layui-form-mid layui-word-aux">{if isset($v['tips'])}{:htmlspecialchars_decode($v['tips'])}{/if}</div>
        </div>
        {/case}
        {default /}
        <!--单行文本-->
        <div class="layui-form-item">
            <label class="layui-form-label">{$v['title']}</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input field-{$v['name']}" name="{$v['name']}" value="{if isset($v['value'])}{$v['value']}{/if}" autocomplete="off" placeholder="{if isset($v['placeholder'])}{$v['placeholder']}{else/}请填写{$v['title']}{/if}"{if isset($v['verify'])} lay-verify="{$v['verify']}"{/if}{if isset($v['attribute']) && $v['attribute']} {$v['attribute']}{/if}>
            </div>
            <div class="layui-form-mid layui-word-aux">{if isset($v['tips'])}{:htmlspecialchars_decode($v['tips'])}{/if}</div>
        </div>
        {/switch}
        {/volist}
        <div class="layui-form-item">
            <label class="layui-form-label no-after"> </label>
            <div class="layui-input-block">
                {if $buildData['buildForm']['token'] == true}{:token_field()}{/if}
                <button type="submit" class="layui-btn layui-btn-normal" lay-submit="" {if isset($buildData['buildForm']['hiData'])}hi-data={:json_encode($buildData['buildForm']['hiData'])}{/if} lay-filter="formSubmit">{$buildData['buildForm']['submitBtn']['title']}</button>
                {if !isset($buildData['buildForm']['hiData']['pop'])}
                <a href="{if $buildData['buildForm']['backBtn'] == true}{:url($buildData['buildForm']['backBtn'])}{else/}javascript:goback(){/if}" class="layui-btn layui-btn-primary ml10"><i class="aicon ai-fanhui"></i>返回</a>
                {/if}
            </div>
        </div>
    </div>
</form>
{if !isset($tabType)}
</div>
{/if}
<script>
    layui.use(['jquery', 'laydate', 'upload', 'func'], function() {
        var $ = layui.jquery, laydate = layui.laydate, layer = layui.layer, upload = layui.upload;
        layui.func.assign({:json_encode($formData)});
        $('.layui-upload').each(function(i) {
            var url = $(this).attr('data-url') == '' ? '{if isset($buildData["buildForm"]["upload_group"])}{:url("system/annex/upload?group=".$buildData["buildForm"]["upload_group"])}{/if}' : $(this).attr('data-url');
            var isMulti = $(this).attr('multi-type');
            var options = {
                elem: $('.layui-upload')[i]
                ,url: url
                ,method: 'post'
                ,before: function(input) {
                    layer.msg('文件上传中...', {time:3000000});
                },done: function(res, obj) {
                    var obj = this.item;
                    if (res.code == 0) {
                        layer.msg(res.msg);
                        return false;
                    }
                    layer.closeAll();
                    if (isMulti) {
                        var field = $(obj).attr('multi-field');
                    }else{
                        var input = $(obj).parents('.upload').find('.upload-input');
                        if ($(obj).attr('lay-type') == 'image') {
                            var imgSrc = res.data.file;
                            if (res.data.domain) {
                                imgSrc = (res.data.protocol > 0 ? 'https' : 'http') + '://' + res.data.domain + '/' + res.data.file;
                            }
                            input.siblings('img').attr('src', imgSrc).show();
                        }
                        if ($(obj).attr('lay-type') == 'file') {
                            if (res.data.domain) {
                                res.data.file = (res.data.protocol > 0 ? 'https' : 'http') + '://' + res.data.domain + '/' + res.data.file;
                            }
                            input.siblings('span').text(res.data.file);
                        }
                    }
                    {if isset($buildData["buildForm"]["upload_info"])}
                    var resData = 'file@' + res.data.file + '|' + 'data_id@' + res.data.data_id + '|' + 'size@' + res.data.size + '|' + 'hash@' + res.data.hash + '|' + 'type@' + res.data.type + '|' + 'ext@' + res.data.ext + '|' + 'group@' + res.data.group + '|' + 'create_time@' + res.data.create_time;
                    if (res.data.driver && res.data.domain) {
                        resData += '|driver@' + res.data.driver + '|domain@' + res.data.domain;
                    }
                    if (res.data.protocol) {
                        resData += '|protocol@' + res.data.protocol;
                    }
                    if(isMulti){
                        $(obj).parents('.upload').find('.multi-priview').append('<li class="item_img"><div class="operate"><i class="close layui-icon">&#xe640;</i></div><a href="' + res.data.file + '" target="_blank"><img src="' + res.data.file + '" type="multi" class="field-'+field+'" ></a><input type="hidden" name="'+field+'[]" value="' + resData + '" /></li>');
                    }else{
                        input.val(resData);
                    }
                    {else}
                    if(isMulti){
                        $(obj).parents('.upload').find('.multi-priview').append('<li class="item_img"><div class="operate"><i class="close layui-icon">&#xe640;</i></div><a href="' + res.data.file + '" target="_blank"><img src="' + res.data.file + '" type="multi" class="field-'+field+'" ></a><input type="hidden" name="'+field+'[]" value="' + res.data.file + '" /></li>');
                    }else{
                        input.val(res.data.file);
                    }
                    {/if}
                }
            };
            upload.render(options);
        });
        /* 绑定多个日期控件 */
        $('.layui-date').each(function(i) {
            laydate.render({
                elem: this
                ,trigger: 'click'
            });
        });
        /* 绑定多个日期时间控件 */
        $('.layui-date-time').each(function(i) {
            laydate.render({
                elem: this
                ,type: 'datetime'
                ,trigger: 'click'
            });
        });
        $("body").on("click", ".close", function(){
            $(this).closest("li").remove();
        });
    });
</script>
<script src="__PUBLIC_STATIC__/p_builder/js/form.js?v={:config('builder.version')}"></script>
{/if}
</body>
</html>